﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script> 
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>客户修改</title>
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
    <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
        <div class="demo-login-container">
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        客户编码
                    </div>

                    <div style="width:400px;left:28px">
                        <input style="width:400px" type="text" name="ClientNo" value="" lay-verify="required" placeholder="请输入客户编码" lay-reqtext="请填写客户编码" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        客户名称
                    </div>
                    <div style="width:500px;left:28px">
                        <input style="width:500px" type="text" name="ClientName" value="" lay-verify="required" placeholder="请输入客户名称" lay-reqtext="请填写客户名称" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        客户简称
                    </div>
                    <div style="width:500px;left:28px">
                        <input style="width:500px" type="text" name="ClientAName" value="" lay-verify="required" placeholder="请输入客户简称" lay-reqtext="请填写客户简称" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix">
                        客户英文名称
                    </div>
                    <input style="width:500px" type="text" name="ClientEname" value="" lay-verify="required" placeholder="请输入客户英文名称" lay-reqtext="请填写客户英文名称" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        客户类型
                    </div>
                    <div style="width:300px;left:30px">
                        <select style="width:300px" id="ClientTypeId">
                            <option value="0">请选择</option>
                            <option value="1">企业客户</option>
                            <option value="2">个人</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:30px">
                        客户简介
                    </div>
                    <div style="width:500px;left:28px">
                        <textarea style="width:1000px" type="textarea" name="ClientSynopsis" value="" lay-verify="required" placeholder="请输入客户简介" lay-reqtext="请填写客户简介" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        客户地址
                    </div>
                    <div style="width:500px;left:28px">
                        <textarea style="width:1000px" type="textarea" name="ClientSite" value="" lay-verify="required" placeholder="请输入客户地址" lay-reqtext="请填写客户地址" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix">
                        客户官网地址
                    </div>
                    <div style="width:300px">
                        <input style="width:300px" type="text" name="ClientWebsite" value="" lay-verify="required" placeholder="请输入客户官网地址" lay-reqtext="请填写客户官网地址" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix">
                        客户邮箱地址
                    </div>
                    <div style="width:300px">
                        <input style="width:300px" type="text" name="ClientEmail" value="" lay-verify="required" placeholder="请输入客户邮箱地址" lay-reqtext="请填写客户邮箱地址" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:10px">
                        客户电话
                    </div>
                    <div style="width:300px;left:10px">
                        <input style="width:300px" type="text" name="ClientPhone" value="" lay-verify="required" placeholder="请输入客户电话" lay-reqtext="请填写客户电话" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:20px">
                        客户LOGO
                    </div>
                    <div style="width:300px;left:20px">
                        <input style="width:300px" type="text" name="ClientLogo" value="" lay-verify="required" placeholder="请输入客户LOGO" lay-reqtext="请填写客户LOGO" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:48px">
                        联系人1
                    </div>
                    <div style="width:300px;left:48px">
                        <input style="width:300px" type="text" name="ClientContact1" value="" lay-verify="required" placeholder="请输入联系人1" lay-reqtext="请填写联系人1" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>

                    <div class="layui-input-prefix" style="left:65px">
                        联系人1-电话
                    </div>
                    <div style="width:300px;left:65px">
                        <input style="width:300px" type="text" name="ClientPhone1" value="" lay-verify="required" placeholder="请输入联系人1-电话" lay-reqtext="请填写联系人1-电话" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>

                    <div class="layui-input-prefix" style="left:61px">
                        联系人1-邮箱
                    </div>
                    <div style="width:300px;left:61px">
                        <input style="width:300px" type="text" name="ClientEmail1" value="" lay-verify="required" placeholder="请输入联系人1-邮箱" lay-reqtext="请填写联系人1-邮箱" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:48px">
                        联系人2
                    </div>
                    <div style="width:300px;left:48px">
                        <input style="width:300px" type="text" name="ClientContact2" value="" lay-verify="required" placeholder="请输入联系人2" lay-reqtext="请填写联系人2" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>

                    <div class="layui-input-prefix" style="left:65px">
                        联系人2-电话
                    </div>
                    <div style="width:300px;left:65px">
                        <input style="width:300px" type="text" name="ClientPhone2" value="" lay-verify="required" placeholder="请输入联系人2-电话" lay-reqtext="请填写联系人2-电话" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>

                    <div class="layui-input-prefix" style="left:61px">
                        联系人2-邮箱
                    </div>
                    <div style="width:300px;left:61px">
                        <input style="width:300px" type="text" name="ClientEmail2" value="" lay-verify="required" placeholder="请输入联系人2-邮箱" lay-reqtext="请填写联系人2-邮箱" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix">
                        统一社会信用代码
                    </div>
                    <div style="width:285px">
                        <input style="width:285px" type="text" name="SocialCreditCode" value="" lay-verify="required" placeholder="请输入统一社会信用代码" lay-reqtext="请填写统一社会信用代码" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:50px">
                        是否启用
                    </div>
                    <div style="width:300px;left:50px">
                        <input type="radio" name="IsVaild" value="1" title="启用" lay-filter="demo-radio-filter" checked>
                        <input type="radio" name="SupplierIsNo" value="0" lay-filter="demo-radio-filter" title="禁用">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:70px">
                        备注
                    </div>
                    <div style="width:500px;left:70px">
                        <textarea style="width:1000px" type="textarea" name="Remark" value="" lay-verify="required" placeholder="请输入备注" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-form-item" style="left:200px">
                            <button class="layui-btn layui-btn-normal" onclick=" UpdateClient()">修改</button>
                        <button class="layui-btn layui-btn-primary" lay-filter="demo-Break">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
   </body>
</html>
<script>
    var form = layui.form;
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var laydate = layui.laydate;
    var laypage = layui.laypage;
    // var obj = {
    //     clientId: 0,
    //     clientNo: "",
    //     clientName: "",
    //     clientAName: "",
    //     clientEname: "",
    //     clientTypeId: 0,
    //     clientSynopsis: "",
    //     clientSite: "",
    //     clientWebsite: "",
    //     clientEmail: "",
    //     clientPhone: "",
    //     clientLogo: "",
    //     clientContact1: "",
    //     clientPhone1: "",
    //     clientEmail1: "",
    //     clientContact2: "",
    //     clientPhone2: "",
    //     clientEmail2: "",
    //     socialCreditCode: "",
    //     isVaild: 0,
    //     remark: "",
    // };

    $(function () {
        GetClientType();
    });

        function GetClientType() { 
            return new Promise(function (resolve, reject) { 
                $(document).ready(function () {
                    var clientId=localStorage .getItem("clientId");
                    console .log(clientId);
                    if (clientId) {
                        $.ajax({
                        type: "post",
                        url: '@ViewBag.FoundationWrite' + '/api/Jocker/ClientManagementBack',
                        data: JSON.stringify({ ClientId: clientId }),
                        asyn: false,
                        dataType: "json",
                        contentType: "application/json",
                        success: function (res) {
                                if (res.data) {
                                    const cli=res.data;
                                    $("[name='ClientNo']").val(cli[0].clientNo);
                                    $("[name='ClientName']").val(cli[0].clientName);
                                    $("[name='ClientAName']").val(cli[0].clientAName);
                                    $("[name='ClientEname']").val(cli[0].clientEname);
                                    $("#ClientTypeId").val(cli[0].clientTypeId);
                                layui.form.render('select');
                                $("[name='ClientSynopsis']").val(cli[0].clientSynopsis);
                                    $("[name='ClientSite']").val(cli[0].clientSite);
                                    $("[name='ClientWebsite']").val(cli[0].clientWebsite);
                                    $("[name='ClientEmail']").val(cli[0].clientEmail);
                                    $("[name='ClientPhone']").val(cli[0].clientPhone);
                                    $("[name='ClientLogo']").val(cli[0].clientLogo);
                                    $("[name='ClientContact1']").val(cli[0].clientContact1);
                                    $("[name='ClientPhone1']").val(cli[0].clientPhone1);
                                    $("[name='ClientEmail1']").val(cli[0].clientEmail1);
                                    $("[name='ClientContact2']").val(cli[0].clientContact2);
                                    $("[name='ClientPhone2']").val(cli[0].clientPhone2);
                                    $("[name='ClientEmail2']").val(cli[0].clientEmail2);
                                    $("[name='SocialCreditCode']").val(cli[0].socialCreditCode);
                                    $("[name='IsVaild']").val(cli[0].isVaild);
                                    $("[name='Remark']").val(cli[0].remark);
                                    resolve(cli);
                            }else{
                                    layer.msg(res.message);
                            }
                            form.render();
                            }
                        });         
                                        
                    }

                });
            });
        }


        function UpdateClient(){
            var clientId=localStorage .getItem("clientId");
            let aa = {
                ClientId: clientId,
                ClientNo: $("[name='ClientNo']").val(),
                ClientName: $("[name='ClientName']").val(),
                ClientAName: $("[name='ClientAName']").val(),
                ClientEname: $("[name='ClientEname']").val(),
                ClientTypeId: $("#ClientTypeId").val(),
                ClientSynopsis: $("[name='ClientSynopsis']").val(),
                ClientSite: $("[name='ClientSite']").val(),
                ClientWebsite: $("[name='ClientWebsite']").val(),
                ClientEmail: $("[name='ClientEmail']").val(),
                ClientPhone: $("[name='ClientPhone']").val(),
                ClientLogo: $("[name='ClientLogo']").val(),
                ClientContact1: $("[name='ClientContact1']").val(),
                ClientPhone1: $("[name='ClientPhone1']").val(),
                ClientEmail1: $("[name='ClientEmail1']").val(),
                ClientContact2: $("[name='ClientContact2']").val(),
                ClientPhone2: $("[name='ClientPhone2']").val(),
                ClientEmail2: $("[name='ClientEmail2']").val(),
                SocialCreditCode: $("[name='SocialCreditCode']").val(),
                IsVaild: $("[name='IsVaild']").val(),
                Remark: $("[name='Remark']").val(),
            };
            console.log(aa);
            $.ajax({
                type: "post",
                url: '@ViewBag.FoundationWrite' + '/api/Jocker/ClientManagementUpdate',
                data: JSON.stringify(aa),
                asyn: false,
                dataType: "json",
                contentType: "application/json",
                success: res=> {
                    if (res.code >0) {
                    alert('修改成功');
                    console.log(res);
                    layer.closeAll();
                    } else {
                    alert('修改失败');
                }
                }
            });
        }
  
    </script>